package com.lemon.smartsafety.ui.activity.common;

import android.view.View;

import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.entity.common.AreaVo;
import com.lemon.smartsafety.entity.event.common.AreaSelectEvent;
import com.lemon.smartsafety.http.service.CommonServices;
import com.lemon.smartsafety.listener.AreaType;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.LoggerHelper;

import java.util.List;

/**
 * Created by Cooliean on 16/4/6.
 */
public class AreaVillageActivity extends AreaBaseActivity implements RecyclerTClickListener<AreaVo> {

    private LoggerHelper loggerHelper = new LoggerHelper(AreaVillageActivity.class);


    @Override
    protected void initTitle() {
        setBarTitle("村");
    }


    @Override
    protected void initViews() {
        super.initViews();
    }

    @Override
    public String getTag() {
        return EventTag.TAG_AREA_VILLAGE;
    }

    @Override
    public void getNetData() {
        CommonServices.init().getVillageInfo(mParentId);
    }

    @Override
    public void httpRefresh(List<AreaVo> data) {
        super.httpRefresh(data);
    }

    @Override
    public void onItemClick(AreaVo data, int position) {
        AreaSelectEvent event = new AreaSelectEvent();
        event.setTag(AreaSelectEvent.class.getName());
        event.setData(data);
        event.setType(AreaType.VILLAGE);
        AppService.getBus().post(event);
        finishAllArea();
        /*
        if (!data.isHasChild()) {
            AreaSelectEvent event = new AreaSelectEvent();
            event.setTag(AreaSelectEvent.class.getName());
            event.setData(data);
            event.setType(AreaType.VILLAGE);
            AppService.getBus().post(event);
            callFinish();
        }else{
            Bundle bundle = new Bundle();
            bundle.putBoolean(BundleKey.IS_FOR_REGISTER, isForRegister);
            bundle.putString(BundleKey.AREA_PARENT_ID, data.getVoId());
            bundle.putString(BundleKey.AREA_PARENT_TITLE, data.getTitle());
            UIHelper.showActivity(this, bundle, AreaVillageActivity.class);
        }
        */
    }
    @Override
    public void doSelect() {
        AreaSelectEvent event = new AreaSelectEvent();
        event.setTag(AreaSelectEvent.class.getName());
        event.setData(null);
        event.setType(AreaType.VILLAGE);
        finishAllArea();
    }

    private void finishAllArea(){
        AppManager.getAppManager().finishActivity(AreaVillageActivity.class);
        AppManager.getAppManager().finishActivity(AreaStreetActivity.class);
        AppManager.getAppManager().finishActivity(AreaDistrictActivity.class);
        AppManager.getAppManager().finishActivity(AreaCityActivity.class);
        AppManager.getAppManager().finishActivity(AreaProvinceActivity.class);
    }



    @Override
    public void onHeadClick(View view) {
        AreaSelectEvent event = new AreaSelectEvent();
        event.setTag(AreaSelectEvent.class.getName());
        event.setData(null);
        event.setType(AreaType.VILLAGE);
        AppService.getBus().post(event);
        callFinish();
    }
}
